package asionreachel.cn.smarthomedemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.widget.FrameLayout;

import asionreachel.cn.smarthomedemo.R;
import asionreachel.cn.smarthomedemo.base.BaseActivity;
import asionreachel.cn.smarthomedemo.monitor.JLoginMonitor;
import asionreachel.cn.smarthomedemo.service.JMonitorService;
import asionreachel.cn.smarthomedemo.utils.Mlog;

public class LogoActivity extends BaseActivity {

    private FrameLayout rootLayout;

    private static final int sleepTime = 2000;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        Intent intentMonitorService = new Intent( this, JMonitorService.class );
        startService( intentMonitorService );

        if( null != JLoginMonitor.GetInstance() && JLoginMonitor.GetInstance().GetLastCheckLogined() )
        {
            Intent intent = new Intent(mActivity , LoginActivity.class);
            startActivity(intent);
            finish();
            return;
        }

        setContentView(R.layout.activity_logo);
        mActivity = this;
        rootLayout = (FrameLayout) findViewById(R.id.splash_fl_root);

        AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);
        animation.setDuration(1500);
        if (rootLayout == null) {
            Mlog.e("为空");
        } else {
            Mlog.e("不为空");
        }

        rootLayout.startAnimation(animation);
    }

    @Override
    protected void onStart() {
        super.onStart();

        new Thread(new Runnable() {
            public void run() {

                try {
                    Thread.sleep(sleepTime);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Intent intent = new Intent(mActivity , LoginActivity.class);
                startActivity(intent);
                finish();
            }
        }).start();

    }

    /**
     * 登录
     */
    private void onLogin(final String account, final String pass) {
        startActivity(new Intent(LogoActivity.this, LoginActivity.class));
        finish();
//        JLoginPlan plan = new JLoginPlan(account, pass);
//        JCtrlThread.GetHandler().Send(plan);
//        plan.setOnRequestListener(new BasePlan.OnRequestListener() {
//            @Override
//            public void onSuccess(BasePlan plan) {
//
//                startActivity(new Intent(SplashActivity.this, MainActivity.class));
//                finish();
//            }
//
//            @Override
//            public void onFail(BasePlan plan) {
//                startActivity(new Intent(SplashActivity.this, LoginActivity.class));
//                finish();
//            }
//
//            @Override
//            public void onEnd() {
//
//            }
//        });
    }
}
